|
|
|
|
|
|
|
Figure 16.8
Specular reflection decreases quickly as the angle f increases. |
|
|
|
|
|
|
|
|
the X component of vector A is Ax = Lx + Bx. You can turn this around slightly to see that B = A L. |
|
|
|
|
|
|
|
|
The geometry of the situation implies that the length of A is |L| * Cos(q). Because L is a unit vector, |L| = 1, so this becomes simply Cos(q). The vector A lies along the unit normal N, so the exact value for A is N * Cos(q). Because L and N are unit vectors, the dot product L < N = Cos(q). |
|
|
|
|
|
|
|
|
Putting these results together, you get B = A L = N * (L < N) L. |
|
|
|
|
|
|
|
|
Finally, Figure 16.9 shows that R = L + 2 * B. Substituting the value for B gives R = L + 2 * (N * (L < N) L) = 2 * N * (L < N) L. You can use this equation to compute the vector R in terms of the vectors N and L. For instance, the X component of the vector R is given by the equation: |
|
|
|
 |
|
|
|
|
Rx = 2 * Nx * (Lx * Nx + Ly * Ny + Lz * Nz) - Lx |
|
|
|
|
|
|
|
|
Using these results, you can update the SurfaceColor subroutine used by the Face3d class. The following code show the routine in its entirety. |
|
|
|
 |
|
|
|
|
' Return the proper shade for this face
' due to the indicated light source. Private Function SurfaceColor( _
ByVal light_sources As Collection, _
ByVal ambient_light As Integer, ByVal eye_x As Single, _ |
|
|
|
|
|
|
|
|
Figure 16.9
Calculating the mirror direction R. |
|
|
|
|
|